<?php
if(!isset($dbselect)) //前面没设置 数据库 则指定使用 DB3
    $dbselect   = Db::G3();
///关于标收费信息的统计
$sfwhere      = "";
if($startdate!="" && $enddate!=""){
  $sfwhere    = " and qtime_h>='$startdate' and qtime_h<='$enddate'";  
} 
$rows = $dbselect->GetRows("SELECT sum(if(flowty='hklirun',-money,0)) as 利润, sum(if(flowty='hklirun',1,0)) as 利润次数,
sum(if(flowty='faxitocom',-money,0)) as 罚息利润, sum(if(flowty='faxitocom',1,0)) as 罚息次数,
sum(if(flowty='jiangli',-money,0)) as 发放奖励, sum(if(flowty='jiangli',1,0)) as 奖励次数,
cid,SUBSTR( qtime_h, 1, 10 ) as qtime_h
FROM  `04a_5flow_bid` f  left join 05b_0base b on f.bid =b.bid
WHERE  `flowty` IN ('hklirun',  'faxitocom','jiangli') $sfwhere
group by cid,SUBSTR( qtime_h, 1, 10 )");
foreach($rows as &$row){
    $cid    = $row['cid'];
    $ctime  = strtotime($row['qtime_h']);
    $Y      = date("Y", $ctime);
    $M      = date("n", $ctime);
    $D      = date("j", $ctime); 
    $count  = $row['利润次数'];
    $c_fx   = $row['罚息次数'];
    $c_jl   = $row['奖励次数'];
  ///对于标一些特殊的资金变动的特殊统计 
   if($c_fx>0){
       CTLog::G()->doctAndDayReal($c_fx.",rp_{$Y}{$m}_st01",1,"tot_yq_get_faxi",$row['罚息利润'],$Y,$M,$D); //逾期还款罚息利润
       CTLog::G()->doctAndDayReal($c_fx.",rp_{$Y}{$m}_cid",$cid,"tot_yq_get_faxi",$row['罚息利润'],$Y,$M,$D);
   }
   if($c_jl>0){
       CTLog::G()->doctAndDayReal($c_jl.",rp_{$Y}{$m}_st01",1,"ttot_jiangli",$row['发放奖励'],$Y,$M,$D); //逾期还款罚息利润
       CTLog::G()->doctAndDayReal($c_jl.",rp_{$Y}{$m}_cid",$cid,"ttot_jiangli",$row['发放奖励'],$Y,$M,$D);
   }
   if($count>0){
       CTLog::G()->doctAndDayReal($count.",rp_{$Y}{$m}_st01",1,'tot_site_celirun',$row['利润'],$Y,$M,$D);     //差额利润
       CTLog::G()->doctAndDayReal($count.",rp_{$Y}{$m}_cid",$cid,"tot_site_celirun",$row['利润'],$Y,$M,$D);
   }
}